package com.example.userservice.controller;

import com.example.userservice.client.EnrollClient;
import com.example.userservice.entity.user_account;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class EnrollmentController {
    @Autowired
    private EnrollClient enrollClient;
    @PostMapping("/student/enroll")
    @ResponseBody
    public String enrollCourse(@RequestParam int courseId, HttpSession session) {
        user_account user = (user_account) session.getAttribute("user");
        if (user == null) {
            return "未登录";
        }

        Map<String, Object> body = new HashMap<>();
        body.put("userId", user.getId());
        body.put("courseId", courseId);
        body.put("remark", "学生自主选课");

        return enrollClient.createEnrollment(body);
    }
}
